package com.digitalchina.user.service;

import com.digitalchina.user.dao.UserInfoMapper;
import com.digitalchina.user.dao.UserMapper;
import com.digitalchina.user.model.User;
import com.digitalchina.user.model.UserInfo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 *
 * Created by zhouxiaa on 2017/7/11.
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    /*
       运营后台登陆
     */
    public Integer selectBy(Map map){
        return userMapper.selectBy(map);
    }
    /**
     * 会员管理，查询列表
     * */
    public List<UserInfo> selectList(Map map){
        return userInfoMapper.selectList(map);
    }
    /**
     * 会员管理，查询列表和
     * */
    public Integer selectCount(Map map){
        return userInfoMapper.selectCount(map);
    }
    /**
     * 会员管理，编辑会员
     * */
    public Integer update(UserInfo record){
        return userInfoMapper.updateByPrimaryKeySelective(record);
    }
    /**
     * 会员管理，查询详情
     * */
    public UserInfo detail(Integer id){
        UserInfo userIfo = userInfoMapper.selectByPrimaryKey(id);
        if(userIfo.getIndustryin()!=null && !userIfo.getIndustryin().equals("")){
            userIfo.setIndustryin(changeName(Integer.valueOf(userIfo.getIndustryin())));
        }
        if(userIfo.getIntrestIndus()!=null && !userIfo.getIntrestIndus().equals("")){
            String intrestIndus = "";
            String[] intrestIndusId = userIfo.getIntrestIndus().split(",");
            for(int i = 0; i<intrestIndusId.length;i++){
                intrestIndus += changeName(Integer.valueOf(intrestIndusId[i]));
                if(i!=intrestIndusId.length-1){
                    intrestIndus += ",";
                }
            }
            userIfo.setIntrestIndus(intrestIndus);
        }
        return userIfo;
    }

    public  String changeName(Integer id){
        return userInfoMapper.getName(id);
    };

    public User getUser(Map map) {

        return userMapper.getUser(map);
    }
}
